<template>
    <div>
        <div class="container">
            <div class="uploadResult">
                <div class="container_success">
                    <div class="msg" v-if="state === 'success'">
                        <div class="icon">
                            <img :src="icon.success" alt="" />
                        </div>
                        <div class="title">导入成功</div>
                        <div v-if="showDataResult">
                            成功导入{{ successLength }}条数据
                        </div>
                    </div>
                    <div class="msg" v-if="state === 'error'">
                        <div class="icon">
                            <img :src="icon.error" alt="" />
                        </div>
                        <div class="title">导入失败</div>
                        <div class="errorInfo" v-if="result.errorMsg">
                            {{ result.errorMsg }}
                        </div>
                        <div class="downloadInfo" v-else>
                            <span v-if="showDataResult"
                                >成功导入{{ successLength }}条数据，导入失败{{
                                    errorLength
                                }}条，</span
                            >
                            <el-button
                                class="downloadError"
                                type="text"
                                @click="downloadErr"
                                v-if="showErrorFeedback"
                                >下载失败文档</el-button
                            >
                        </div>
                    </div>
                    <div class="uploadFilesList" v-if="false">
                        <div
                            class="item"
                            v-for="item in result.filelist"
                            :key="item.uid"
                        >
                            <div class="icon">
                                <i class="el-icon-paperclip"></i>
                            </div>
                            <div
                                class="fileContent"
                                :class="[
                                    item.state === 'error'
                                        ? 'error'
                                        : 'success',
                                ]"
                            >
                                <div class="label">
                                    <TooltipDiv
                                        :content="item.name"
                                    ></TooltipDiv>
                                </div>
                                <div class="status">
                                    <i
                                        v-if="item.state === 'error'"
                                        class="el-icon-close"
                                    ></i>
                                    <i
                                        v-if="item.state === 'success'"
                                        class="el-icon-check"
                                    ></i>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import TooltipDiv from "@/views/quota/forecast/chunk/tooltipDiv";
export default {
    name: "",
    components: { TooltipDiv },
    mixins: [],
    props: {
        result: Object,
        showResult: Boolean,
        showErrorFeedback: Boolean,
    },
    data() {
        return {
            icon: {
                success: require("@/assets/images/check-circle@2x.png"),
                error: require("@/assets/images/close-circle@2x.png"),
            },
        };
    },
    computed: {
        state() {
            return this.result.state;
        },
        successLength() {
            return this.result.info?.success ?? 0;
        },
        errorLength() {
            return this.result.info?.error ?? 0;
        },
        showDataResult() {
            return (
                this.showResult &&
                (this.successLength > 0 || this.errorLength > 0)
            );
        },
        successFileLength() {
            return this.result.success?.length ?? 0;
        },
        errorFileLength() {
            return this.result.error?.length ?? 0;
        },
        showFileResult() {
            return (
                this.showResult &&
                (this.successFileLength > 0 || this.errorFileLength > 0)
            );
        },
    },
    watch: {},
    mounted() {},
    methods: {
        downloadErr() {
            this.download_get(this.result.errUrl, {}, `失败数据.xlsx`);
        },
    },
};
</script>
<style lang="scss" scoped>
.container {
    // width: 300px;
    background: #fff;
    display: flex;
    justify-content: center;
    padding: 20px 0;
}
.tips {
    align-self: flex-start;
}
.uploadBox {
    width: 440px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.content {
    height: 100%;
    border: 1px dashed #d9d9d9;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    .text {
        font-size: 16px;
        color: #606266;
        margin-top: 10px;
    }
}
::v-deep .upload-file-uploader {
    display: flex;
    flex-direction: column;
    .el-upload {
        margin: 0 auto;
    }
}
::v-deep .el-upload-dragger {
    width: 300px;
    height: 180px;
}
.uploadResult {
    .msg {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 15px;
        .icon {
            width: 80px;

            img {
                width: 100%;
                display: block;
            }
        }
        .title {
            font-weight: bold;
            font-size: 22px;
        }
        .downloadInfo {
            font-size: 14px;
        }
    }
    .uploadFilesList {
        max-height: 200px;
        overflow-y: overlay;
        width: 300px;
        margin: 40px auto 0;
        .item {
            --success: #79a84b;
            --error: red;
            display: flex;
            .icon {
                width: 25px;
                margin-bottom: 20px;
                display: flex;
                align-items: center;
            }
            .fileContent {
                min-width: 0;
                flex: 1;
                border-bottom: 1px solid;
                padding-bottom: 5px;
                margin-bottom: 15px;
                display: flex;
                flex-direction: row;
                justify-content: space-between;
                align-items: center;
                .label {
                    width: 70%;
                    .text {
                        overflow: hidden;
                        white-space: nowrap;
                        text-overflow: ellipsis;
                        margin-top: 0;
                    }
                }
            }
            .success {
                border-color: var(--success);
                .status {
                    i {
                        color: var(--success);
                    }
                }
            }
            .error {
                border-color: var(--error);
                .status {
                    i {
                        color: var(--error);
                    }
                }
            }
        }
    }
}
</style>
